/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.datasource.routing;

import org.springframework.jdbc.datasource.AbstractDataSource;

import javax.sql.DataSource;
import java.io.Closeable;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 抽象路由数据源
 *
 * @auther ebert_chan
 */
public abstract class AbstractRoutingDataSource extends AbstractDataSource implements Closeable {

    /*
     * @see javax.sql.DataSource#getConnection()
     */
    @Override
    public Connection getConnection() throws SQLException {
        return resolveDataSource().getConnection();
    }

    /*
     * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
     */
    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        return resolveDataSource().getConnection(username, password);
    }

    /**
     * 决定设置数据源
     *
     * @return
     * @throws SQLException
     * @auther ebert_chan
     */
    public abstract DataSource resolveDataSource() throws SQLException;

}
